layui.use([  'jquery' ], function () {
    var   $ = layui.jquery;

    function navInit( ) {
        var data = null;
        var parameter = {
            type: "get",
            url: webPath + "/res/json/navitems.json",
            async: true,
            data: {},
            success: function (res) {
                    data = res ;
                    menuInit(res);
            }
        };
        $.ajax(parameter);
        return data;
    }

    function userInit( ) {
        var data = null;
        var parameter = {
            type: "get",
            url: webPath + "/api/getUserName",
            async: true,
            data: {},
            success: function (res) {
                if (res.code == 200 && res.message == "OK") {
                    $('body > div.header > div > div.blog-nav.pull-right > a').attr('href',webPath+'/page/backstage')
                    $('body > div.header > div > div.blog-nav.pull-right > a').html(res.data)
                } else {
                    //layer.msg(res.message)
                }
            }
        };
        $.ajax(parameter);
        return data;
    }

    //菜单
    function menuInit(data) {
        var webHtml = "", phoneHtml = "";
        for (var index in data) {
            var item = data[index];
            webHtml += '<li class="layui-nav-item"><a href="' + item.url + '">' + item.title + '</a></li>';
            phoneHtml += '<li><a href="' + item.url + '">' + item.title + '</a></li>';
        }
        $('body > div.header > div > div.blog-nav.pull-right > ul').html(webHtml);//web
        $('#pop-nav').html(phoneHtml)//手机
    }

    navInit( );
    userInit( );
});